/*
*	New C++ File starts here.
*	This file should be named nml_ex1_c_n.c
*/

/* Include all C language NML and CMS function prototypes. */
#include "nmlcms_c.h"

/* Include externally supplied prototypes. */
#include "nml_ex1_c_n.h"

/* Forward Function Prototypes */
#ifdef __cplusplus
extern "C" {
#endif

void cms_EXAMPLE_MSG_update(struct cms_c_struct *cms, nml_EXAMPLE_MSG_c_t *x);

#ifdef __cplusplus
}
#endif
long nml_ex_open(const char *buf, const char *proc, const char *cfg)
{
	return (long) nml_new(ex_c_format, buf,proc,cfg);
}

int  nml_ex_valid(long nml_id)
{
	return (int) nml_valid( (nml_c_t) nml_id);
}

void nml_ex_close(long nml_id)
{
	nml_free( (nml_c_t) nml_id);
}

int nml_ex_read(long nml_id)
{
	return (long) nml_read( (nml_c_t) nml_id);
}

int nml_ex_EXAMPLE_MSG_write(long nml_id, const nml_EXAMPLE_MSG_c_t *msg){
	return (int) nml_write( (nml_c_t) nml_id,(void *) msg, (nmltype_c_t) 101,sizeof(nml_EXAMPLE_MSG_c_t));
}

nml_EXAMPLE_MSG_c_t * nml_ex_EXAMPLE_MSG_get_msg(long nml_id){
	return (nml_EXAMPLE_MSG_c_t *) nml_get_address( (nml_c_t) nml_id);
}




#ifndef MAX_EX_C_NAME_LENGTH
#define MAX_EX_C_NAME_LENGTH 12
#endif
#ifndef EX_C_NAME_LIST_LENGTH
#define EX_C_NAME_LIST_LENGTH 2
#endif


/* This list must be in alphabetical order and the three lists must correspond. */
const char ex_c_name_list[EX_C_NAME_LIST_LENGTH][MAX_EX_C_NAME_LENGTH]= {
	"EXAMPLE_MSG", /* 0,101 */
	""};
const NMLTYPE ex_c_id_list[EX_C_NAME_LIST_LENGTH]= {
	EXAMPLE_MSG_TYPE, /* 0,101 */
	-1};
const size_t ex_c_size_list[EX_C_NAME_LIST_LENGTH]= {
	sizeof(nml_EXAMPLE_MSG_c_t),
	0};
const char *ex_c_symbol_lookup(long type);


/* Enumerated Type Constants */

/*
*	NML/CMS Format function : ex_c_format
*	Automatically generated by NML CodeGen Java Applet.
*/
int ex_c_format(long type, void *buffer, struct cms_c_struct *cms)
{

	type = cms_check_type_info(cms,type,buffer,"ex_c",
		(cms_symbol_lookup_function_t) ex_c_symbol_lookup,
		(const char **)ex_c_name_list,
		ex_c_id_list,ex_c_size_list,
		EX_C_NAME_LIST_LENGTH,
		MAX_EX_C_NAME_LENGTH);

	switch(type)
	{
	case EXAMPLE_MSG_TYPE:
		cms_EXAMPLE_MSG_update(cms,(nml_EXAMPLE_MSG_c_t *) buffer);
		break;

	default:
		return(0);
	}
	return 1;
}


/* NML Symbol Lookup Function */
const char *ex_c_symbol_lookup(long type)
{
	switch(type)
	{
	case EXAMPLE_MSG_TYPE:
		return "EXAMPLE_MSG";
	default:
		return"UNKNOWN";
		break;
	}
	return(NULL);
}

/*
*	NML/CMS Update function for EXAMPLE_MSG
*	Automatically generated by NML CodeGen Java Applet.
*/
void cms_EXAMPLE_MSG_update(struct cms_c_struct *cms, nml_EXAMPLE_MSG_c_t *x)
{

	cms_begin_class(cms,"EXAMPLE_MSG","NMLmsg");
	cms_update_double(cms,"d",&(x->d));
	cms_update_float(cms,"f",&(x->f));
	cms_update_char(cms,"c",&(x->c));
	cms_update_short(cms,"s",&(x->s));
	cms_update_int(cms,"i",&(x->i));
	cms_update_long(cms,"l",&(x->l));
	cms_update_unsigned_char(cms,"uc",&(x->uc));
	cms_update_unsigned_short(cms,"us",&(x->us));
	cms_update_unsigned_int(cms,"ui",&(x->ui));
	cms_update_unsigned_long(cms,"ul",&(x->ul));
	cms_update_int(cms,"da_length",&(x->da_length));
	cms_update_double_dla(cms,"da",x->da, &(x->da_length),20);

	cms_end_class(cms,"EXAMPLE_MSG","NMLmsg");

}

